﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.controls {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.events.*;
    import flash.display.*;
    import reprise.core.*;
    import flash.ui.*;

    public class AbstractButton extends AbstractInput {

        protected var m_isToggleButton:Boolean;// = false
        protected var m_selected:Boolean;// = false
        protected var m_enabled:Boolean;// = true

        public function get enabled():Boolean{
            return (m_enabled);
        }
        override protected function handleKeyEvent(_arg1:KeyboardEvent):Boolean{
            switch (_arg1.keyCode){
                case Keyboard.SPACE:
                    dispatchEvent(new MouseEvent(MouseEvent.CLICK));
                    return (true);
                default:
                    return (false);
            };
        }
        public function set enabled(_arg1:Boolean):void{
            if (_arg1 == m_enabled){
                return;
            };
            m_enabled = _arg1;
            if (!_arg1){
                addCSSPseudoClass("disabled");
                removeCSSPseudoClass("hover");
                removeCSSPseudoClass("down");
            } else {
                removeCSSPseudoClass("disabled");
            };
            invalidate();
        }
        protected function buttonDisplay_over(_arg1:MouseEvent):void{
            if (m_enabled){
                addCSSPseudoClass("hover");
            };
        }
        override protected function initialize():void{
            super.initialize();
            m_canBecomeKeyView = true;
            initializeButtonHandlers();
        }
        protected function buttonDisplay_down(_arg1:MouseEvent):void{
            stage.addEventListener(MouseEvent.MOUSE_UP, buttonDisplay_up);
            if (m_enabled){
                addCSSPseudoClass("active");
            };
        }
        override public function setFocus(_arg1:Boolean, _arg2:String):void{
            super.setFocus(_arg1, _arg2);
            if (((_arg1) && (stage))){
                stage.focus = this;
            };
        }
        protected function buttonDisplay_up(_arg1:MouseEvent):void{
            removeCSSPseudoClass("active");
            if (!(((_arg1.target == this)) || (contains(DisplayObject(_arg1.target))))){
                dispatchEvent(new MouseEvent(MouseEventConstants.MOUSE_UP_OUTSIDE));
            };
        }
        public function get selected():Boolean{
            return (m_selected);
        }
        public function set isToggleButton(_arg1:Boolean):void{
            m_isToggleButton = _arg1;
        }
        protected function initializeButtonHandlers():void{
            addEventListener(MouseEvent.MOUSE_OVER, buttonDisplay_over);
            addEventListener(MouseEvent.MOUSE_OUT, buttonDisplay_out);
            addEventListener(MouseEvent.MOUSE_DOWN, buttonDisplay_down);
            addEventListener(MouseEvent.CLICK, buttonDisplay_click);
        }
        override public function setValue(_arg1):void{
            selected = Boolean(_arg1);
        }
        public function get isToggleButton():Boolean{
            return (m_isToggleButton);
        }
        override public function value(){
            return (selected);
        }
        protected function deactivate():void{
            removeCSSPseudoClass("checked");
            m_selected = false;
        }
        protected function buttonDisplay_click(_arg1:MouseEvent):void{
            if (!m_enabled){
                _arg1.stopImmediatePropagation();
                return;
            };
            if (m_canBecomeKeyView){
                m_rootElement.setFocusedElement(this, FocusManager.FOCUS_METHOD_MOUSE);
            };
            if (isToggleButton){
                if (selected){
                    selected = false;
                } else {
                    selected = true;
                };
            };
        }
        protected function activate():void{
            addCSSPseudoClass("checked");
            m_selected = true;
        }
        public function set selected(_arg1:Boolean):void{
            if (_arg1 == m_selected){
                return;
            };
            if (_arg1){
                activate();
            } else {
                deactivate();
            };
        }
        protected function buttonDisplay_out(_arg1:MouseEvent):void{
            removeCSSPseudoClass("hover");
        }

    }
}//package reprise.controls 
